package com.yihaodian.server.servlet;

import javax.servlet.FilterConfig;
import javax.servlet.ServletException;

import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrCore;
import org.apache.solr.handler.admin.CollectionsHandler;
import org.apache.solr.servlet.SolrDispatchFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.yihaodian.indices.SolrContainerFactory;

public class SearchDispatchFilter extends SolrDispatchFilter{
	
	final Logger log=LoggerFactory.getLogger(SearchDispatchFilter.class);
	 @Override
	  public void init(FilterConfig config) throws ServletException
	  {
	    log.info("SearchDispatchFilter.init()");

	    CoreContainer.Initializer init = createInitializer();
	    try {
	      // web.xml configuration
	      this.pathPrefix = config.getInitParameter( "path-prefix" );

	      this.cores = SolrContainerFactory.getCoreContainer();
	      log.info("user.dir=" + System.getProperty("user.dir"));
	    }
	    catch( Throwable t ) {
	      // catch this so our filter still works
	      log.error( "Could not start Solr. Check solr/home property and the logs");
	      SolrCore.log( t );
	    }

	    log.info("SearchDispatchFilter.init() done");
	  }
	

}
